// https://leetcode.cn/problems/find-minimum-in-rotated-sorted-array/
// Created by ade on 2022/8/23.
//
#include <iostream>
#include <vector>


using namespace std;

class Solution {
public:
    int findMin(vector<int> &nums) {
        int left = 0, right = nums.size() - 1;
        if (nums[left] < nums[right]) return nums[left];

        while (nums[left] > nums[right]) {
            int mid = (left + right) / 2;
            if (nums[mid] > nums[right]) {
                left = mid + 1;
            } else {
                right = mid;
            }
        }
        return nums[left];
    }
};

int main() {
    Solution so;
    vector<int> nums = {12, 13, 14, 15};
    cout << so.findMin(nums);
    return 0;
}